package shejimoshi.xiangyuanmoshi;

import java.util.HashMap;
import java.util.Map;

// 享元工厂
public class FlyweightFactory {
    private Map<String, ConcreteFlyweight> flyweights = new HashMap<>();

    public ConcreteFlyweight getFlyweight(String intrinsicState) {
        if (!flyweights.containsKey(intrinsicState)) {
            flyweights.put(intrinsicState, new ConcreteFlyweight(intrinsicState));
        }
        return flyweights.get(intrinsicState);
    }
}
